# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=wpa2-halfhandshake-crack
pkgver=29.3f42124
pkgrel=3
groups=('blackarch' 'blackarch-wireless' 'blackarch-cracker')
pkgdesc='A POC to show it is possible to capture enough of a handshake with a user from a fake AP to crack a WPA2 network without knowing the passphrase of the actual AP.'
arch=('any')
url='https://github.com/dxa4481/WPA2-HalfHandshake-Crack'
license=('MIT')
depends=('python2' 'python2-pcapfile' 'python2-pbkdf2_ctypes')
makedepends=('git' 'python2-setuptools')
source=("$pkgname::git+https://github.com/dxa4481/WPA2-HalfHandshake-Crack.git")
sha512sums=('SKIP')

prepare() {
  cd $pkgname

  sed -i '1 i\#!/usr/bin/python2' halfHandshake.py
}

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  python2 setup.py install --root="$pkgdir" --optimize=1

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md wifihacking.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm -rf README.md wifihacking.md LICENSE WPA2_HalfHandshake_Crack.egg-info

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 halfHandshake.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

